package search;

public class OrderSearch {
	private static int[] unorderArray = new int[]{1,8,6,12,5,266,34,29,55,87,1234,33,23};
	public static int search1(int key){
		for(int i=0;i<unorderArray.length;i++){
			if(key == unorderArray[i]){
				return i;
			}
		}
		return -1;
	}
	
	public static int search2(int key){
		//相比search1减少了数组越界的判断
		int i=unorderArray.length-1;
		if(unorderArray[0]==key){
			return 0;
		}else{
			unorderArray[0]=key;
		}
		while(unorderArray[i]!=key){
			i--;
		}
		return i;
	}
	
	public static void main(String[] args) throws Exception{
		System.out.println("position:"+search1(5));
		System.out.println("position:"+search1(67));
		System.out.println("position:"+search2(5));
	}
}
